/*
 * @author java_deng
 * @date 2025/3/11 21:11
 * @description
 */
package org.kaka.controller;

import org.kaka.dto.EmpDto;
import org.kaka.dto.InstitutionDto;
import org.kaka.service.impl.EmpService;
import org.kaka.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpController extends BaseController{
    @Autowired
    private EmpService empService;

    @RequestMapping("/list")
    public ResponseData list(EmpDto empDto){
        List<EmpDto> list = empService.list(empDto);
        return success(list,list.size());
    }
    @RequestMapping("/get/{id}")
    public ResponseData get(@PathVariable Long id ){
        EmpDto detail = empService.detail(id);
        return success(detail,0);
    }

    @RequestMapping("/saveOrUpdate")
    public ResponseData saveOrUpdate(EmpDto empDto){
        Long id = empDto.getId();
        if(id==null){
            empService.save(empDto);
            return success("新增成功");
        }else {
            empService.update(empDto);
            return success("修改成功");
        }
    }

    @RequestMapping("/delete/{id}")
    public ResponseData delete(@PathVariable Long id){
        if(id==null){
            return fail("id不能为空");
        }else {
            empService.delete(id);
            return success("删除成功");
        }
    }
}
